.PHONY: clean all 
CC      = gcc
LD      = gcc

OS := $(shell uname)
ifeq ($(OS),Darwin)
UNAME= $(OS)
else
UNAME :=$(shell lsb_release -si)
endif

INSTALL_DIR = /opt/tc32/bin
INSTALL = /usr/bin/install -c 
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644


ifeq ($(UNAME),Ubuntu) 
LIBUSB1_CFLAGS = -I/usr/include -std=gnu99 -I/usr/include/libusb-1.0/
LIBUSB1_LIBS =  -L/usr/lib/x86_64-linux-gnu
#else
#LIBUSB1_CFLAGS = -isystem  -I/usr/local/include -I/usr/local/include/libusb-1.0/ -std=gnu99
#LIBUSB1_LIBS = -L/usr/local/lib -lusb-1.0  
#old mingw
else 
LIBUSB1_CFLAGS = -isystem  -I/usr/include -I/usr/include/libusb-1.0/ -std=gnu99
LIBUSB1_LIBS = -L/usr/bin -lusb-1.0  
endif



TARGET	= tcdb 
#CFLAGS  = -DTDEBUG  $(LIBUSB1_CFLAGS) -DSTANDALONE
CFLAGS  = -O2 $(LIBUSB1_CFLAGS) -DSTANDALONE
LDFLAGS = $(LIBUSB1_LIBS) -Wunused-function
CFILES = cmdfunc.c tcdb.c tlink_usb.c usbprn.c
#CFILES = xusb.c
OBJFILES = $(CFILES:%.c=%.o)


all: $(TARGET) install
	
install: $(TARGET)
	$(INSTALL_PROGRAM) $(TARGET) $(INSTALL_DIR)

%.o: %.c
	@echo Compiling $<
	$(CC) $(CFLAGS) -c $< -o $@



$(TARGET): $(OBJFILES)
	@echo Linking  $@
ifeq ($(UNAME),Ubuntu) 
	$(LD) $(LDFLAGS) -o $@ $(OBJFILES)  -lusb-1.0
else
	$(LD) $(LDFLAGS) -o $@ $(OBJFILES) -lusb-1.0
endif


clean:
	@echo Removing files
	rm $(TARGET) *.o *.out output cscope* tags
